package cn.edu.ctbu.simplescoremanagementsystem.aspect;

import cn.edu.ctbu.simplescoremanagementsystem.exception.ResultException;
import cn.edu.ctbu.simplescoremanagementsystem.utils.ResultUtils;
import cn.edu.ctbu.simplescoremanagementsystem.vo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ExceptionHandle {
    @ExceptionHandler(value = Exception.class)
    public Result handle(Exception e){
        if(e instanceof ResultException){
            ResultException resultException = (ResultException) e;
            return ResultUtils.error(resultException.getCode(),resultException.getMessage());
        }else{
            return ResultUtils.error(-1,"未知错误");
        }
    }
}
